<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
        <title>Welcome to Design Zone......</title>
        <link rel="stylesheet" type="text/css" href="../../scripts/ext/resources/css/ext-all.css" />
        <link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
        <script type="text/javascript" src="../../scripts/ext/adapter/ext-base.js">
        </script>
        <script type="text/javascript" src="../../scripts/ext/ext-all.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/EditableItem.js">
        </script>
        <script type="text/javascript" src="../../scripts/menu/RangeMenu.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/GridFilters.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/Filter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/StringFilter.js">
        </script>
        <script type="text/javascript" src="../../scripts/grid/filter/ListFilter.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/filter/DateFilter.js">
        </script>
		<script type="text/javascript" src="../../scripts/grid/RowExpander.js">
        </script>
        <script type="text/javascript" src="../../scripts/i18nMessage.js">
        </script>
        <script type="text/javascript" src="../../scripts/utils.js">
        </script>
        <script type="text/javascript">
        	var ppMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.package');
            var message = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=message');
			var fcMessage = new i18nMessage('../../servlet/I18nMessageServlet?keyPrefix=ui.francecustomer');
			
			var idValue = getPrarmeterValue(window.location, 'id');
            var startPage = getPrarmeterValue(window.location, 'startPage');
			
			var customerXmlLoader = new xmlLoader('../../servlet/BiFranceCustomerServlet?action=5');
			var customerStore;
			var customerCombo;
			
			Ext.onReady(function(){
                Ext.QuickTips.init();
                Ext.form.Field.prototype.msgTarget = 'side';
				
				customerStore = new Ext.data.Store({
                    reader: new Ext.data.XmlReader({
                        record: 'item',
                        id: 'id',
                        totalRecords: 'itemTotal'
                    }, [ 
                    'id', 'name', 'linkman', 'address', 'department']),
					data: customerXmlLoader.getXml()
                });
				
				customerCombo = new Ext.form.ComboBox({
					fieldLabel: message.get('message.edit.customername'),
					id: 'customerID',
					name: 'customerID',
					allowBlank: false,
                    blankText: message.get('message.edit.noblank'),
					editable: false,
					tpl: '<tpl for="."><div class="x-combo-list-item">{name}--{department}</div></tpl>',
					valueField: 'id',
				    store: customerStore,
				    displayField:'name',
				    triggerAction: 'all',
				    emptyText: message.get('message.combo.pleaseselect'),
				    selectOnFocus:true,
					mode: 'local',
                    listeners: {
                        'select': {
                            fn: function(combo, record, index){
								document.getElementById('recipient').value = record.data.address;
                            }
                        }
                    }
				});
				
				var productPackageFrom = new Ext.FormPanel({
					labelAlign: 'left',
					url: '../../servlet/ProductPackageServlet?action=1',
			        frame:true,
			        title: ppMessage.get('ui.package.edittitle'),
			        bodyStyle:'padding:5px 5px 5px 5px;margin-top: 2px;',
			        width: '100%',
					labelWidth: 105,
					reader: new Ext.data.XmlReader({
                        record: 'item'
                    }, [{
                        name: 'id',
                        mapping: 'id'
                    }, {
                        name: 'consignor',
                        mapping: 'consignor'
                    },{
                        name: 'name',
                        mapping: 'name'
                    }, {
                        name: 'recipient',
                        mapping: 'recipient'
                    }, {
                        name: 'unit',
                        mapping: 'unit'
                    }, {
                        name: 'createTime',
                        mapping: 'createTime'
                    },{
                        name: 'invoiceNumber',
                        mapping: 'invoiceNumber'
                    }, {
                        name: 'comment',
                        mapping: 'comment'
                    }, {
                        name: 'customerID',
                        mapping: 'customerID'
                    }]),
					items: [{
	                        id: 'id',
	                        name: 'id',
	                        xtype: 'hidden'
                    	},{
	                        id: 'name',
	                        name: 'name',
							fieldLabel: ppMessage.get('ui.package.name'),
	                        xtype: 'textfield',
							maxLength: 128,
							width: '86%',
							maxLengthText: message.get('message.edit.toolong'),
							allowBlank: false,
	                        blankText: message.get('message.edit.noblank')
                    	},{
							layout: 'column',
							items: [{
								columnWidth:.5,
				                layout: 'form',
								items: [{
	                               	name: 'createTime',
	                                id: 'createTime',
	                                fieldLabel: ppMessage.get('ui.package.createtime') + "(d/m/Y)",
	                                xtype: 'datefield',
									//vtype: 'daterange',
									//startDateField: 'alarmTime',
	                                anchor: '86%',
	                                allowBlank: false,
	                                blankText: message.get('message.edit.noblank')
	                            },{
			                        fieldLabel: ppMessage.get('ui.package.consignor'),
			                        name: 'consignor',
			                        xtype: 'textarea',
			                        maxLength: 512,
									width: '86%',
			                        maxLengthText: message.get('message.edit.toolong'),
									allowBlank: false,
	                                blankText: message.get('message.edit.noblank')
			                    },{
			                        fieldLabel: ppMessage.get('ui.package.unit'),
			                        name: 'unit',
			                        xtype: 'numberfield',
									width: '86%',
			                        maxLengthText: message.get('message.edit.toolong'),
									allowBlank: false,
	                                blankText: message.get('message.edit.noblank')
			                    }]
							},{
								columnWidth:.5,
				                layout: 'form',
								items: [customerCombo,{
			                        fieldLabel: ppMessage.get('ui.package.recipient'),
									id: 'recipient',
			                        name: 'recipient',
			                        xtype: 'textarea',
			                        maxLength: 512,
									width: '86%',
			                        maxLengthText: message.get('message.edit.toolong'),
									allowBlank: false,
	                                blankText: message.get('message.edit.noblank')
			                    },{
			                        fieldLabel: ppMessage.get('ui.package.invoice'),
			                        name: 'invoiceNumber',
			                        xtype: 'textfield',
									width: '86%',
									maxLength: 128,
			                        maxLengthText: message.get('message.edit.toolong'),
									allowBlank: false,
	                                blankText: message.get('message.edit.noblank')
			                    }]
							}]
                    },{
                        fieldLabel: message.get('message.edit.comment'),
                        name: 'comment',
                        xtype: 'textarea',
                        maxLength: 512,
						width: '90%',
                        maxLengthText: message.get('message.edit.toolong')
                    }],
			
			        buttons: [{
			            text: message.get('message.edit.save'),
						handler: function(){
                            if (productPackageFrom.getForm().isValid()) {
								document.getElementsByName('customerID')[0].value = customerCombo.getValue();
								
                                productPackageFrom.getForm().submit({
                                    method: 'post',
                                    success: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.successful'));
                                        productPackageFrom.getForm().reset();
                                    },
                                    failure: function(form, action){
                                        messageTip.msg(message.get('message.tip'), message.get('message.edit.unsuccessful'));
                                    }
                                });
                            }
                        }
			        },{
						text: message.get('message.edit.reset'),
						handler: function(){
							productPackageFrom.getForm().reset();
						}
					},{
			            text: message.get('message.edit.cancel'),
                        handler: function(){
                            if (startPage != null) {
                                window.location = 'product_package_list.html?startPage=' + startPage;
                            }else {
                                window.location = 'product_package_list.html';
                            }
                        }
			        }]
				});
				
				productPackageFrom.render('productPackageForm');
				
				if (idValue != null) {
					productPackageFrom.getForm().load({
							url:'../../servlet/ProductPackageServlet?action=3&id=' + idValue, 
							waitMsg:Ext.LoadMask.prototype.msg, 
							success: function(form, action){
								
							}
					});
				}
				
			});
        
        </script>
    </head>
    <body>
    		<div id="productPackageForm"></div>
    </body>
</html>
